package com.xiaoyun.activiti02;


import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.activiti.engine.query.QueryProperty;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.apache.commons.io.IOUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

/**
 *
 */
public class HistoryQuery {

    public static void main(String[] args) throws IOException {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        HistoryService historyService = processEngine.getHistoryService();

        HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();

        List<HistoricActivityInstance> list = historicActivityInstanceQuery
                .processInstanceId("2501")
                .orderByHistoricActivityInstanceStartTime()
                .asc()
                .list();


        list.stream().forEach(historicActivityInstance -> {
            System.out.println("Id:" + historicActivityInstance.getId());
            System.out.println("Name:" + historicActivityInstance.getActivityName());
            System.out.println("getProcessDefinitionId:" + historicActivityInstance.getProcessDefinitionId());
            System.out.println("getProcessInstanceId:" + historicActivityInstance.getProcessInstanceId());
            System.out.println("======================================");
        });

    }
}
